package io.renren.modules.workmanagement.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.workmanagement.constans.UserConstans;
import io.renren.modules.workmanagement.service.QuestionService;
import io.renren.modules.workmanagement.vo.QuestionAnswerVO;
import io.renren.modules.workmanagement.vo.qu.QuestionInfoVO;
import io.renren.modules.workmanagement.vo.qu.QuestionVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 问题题目
 *
 * @author yewei
 * @email sunlightcs@gmail.com
 * @date 2022-04-17 16:53:10
 */
@RestController
@RequestMapping("workmanagement/question")
public class QuestionController extends AbstractController {
    @Autowired
    private QuestionService questionService;

    @RequestMapping("/getQuestionAnswers")
    public R getQuestionAnswers(@RequestParam Long workId,@RequestParam Long quId){
        QuestionAnswerVO questionAnswers = questionService.getQuestionAnswers(workId,quId,getUserId());
        return R.ok().put("work", questionAnswers);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("teacher:question:list")
    public R list(@RequestParam Map<String, Object> params){
        Long userId = getUserId();
        params.put(UserConstans.USER_ID_KEY, userId);
        PageUtils page = questionService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("teacher:question:info")
    public R info(@PathVariable("id") Long id){
        QuestionInfoVO question = questionService.getQuestionInfoVO(id);

        return R.ok().put("question", question);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("teacher:question:save")
    public R save(@RequestBody QuestionVO question){

		questionService.saveQuestion(question,getUserId());

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("teacher:question:update")
    public R update(@RequestBody QuestionVO question){
		questionService.updateQuestion(question,getUserId());

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("teacher:question:delete")
    public R delete(@RequestBody Long[] ids){
		questionService.removeQuestion(Arrays.asList(ids));

        return R.ok();
    }

}
